from django.db import models


class NewYearsShoppingFestivalElect(models.Model):
    '''年货节评选活动'''

    ACTIVITY_STATE_CHOICES = (
        (0, '待审核'),
        (1, '未开始'),
        (2, '进行中'),
        (3, '已结束')
    )

    available_begin_time = models.DateTimeField(verbose_name='开始时间', null=True, blank=True)
    available_end_time = models.DateTimeField(verbose_name='结束时间', null=True, blank=True)
    activity_description = models.TextField(verbose_name='活动使用说明')
    activity_state = models.SmallIntegerField(verbose_name='活动状态', choices=ACTIVITY_STATE_CHOICES, default=0)
    activity_name = models.CharField(verbose_name='活动名称', max_length=32, null=True, blank=True)

    class Meta:
        db_table = 'tb_new_years_shopping_festival_elect'
        verbose_name = '年货节评选活动'
        verbose_name_plural = verbose_name


class NewYearsShoppingFestivalElectProduct(models.Model):
    '''年货节评选作品'''

    IS_MATCH_CHOICES = (
        (0, '未参赛'),
        (1, '已参赛')
    )

    elect = models.ForeignKey('newyears.NewYearsShoppingFestivalElect', verbose_name='评选活动', on_delete=models.CASCADE)
    product_title = models.CharField(verbose_name='标题', max_length=64)
    product_intro = models.CharField(verbose_name='简介', max_length=256)
    longitude = models.CharField(verbose_name='经度', max_length=32, null=True, blank=True)
    latitude = models.CharField(verbose_name='纬度', max_length=32, null=True, blank=True)
    manageruser = models.ForeignKey('users.User', verbose_name='所属客户经理', on_delete=models.CASCADE)
    level = models.ForeignKey('users.Level', verbose_name='所属地市', on_delete=models.CASCADE)
    like_count = models.IntegerField(verbose_name='点赞数', default=0)
    view_count = models.IntegerField(verbose_name='浏览数', default=0)
    default_image = models.ImageField(max_length=200, default='', null=True, blank=True, verbose_name='默认图片')
    is_match = models.SmallIntegerField(verbose_name='是否参赛', choices=IS_MATCH_CHOICES, default=0)
    product_url = models.CharField(verbose_name='链接', max_length=128, null=True, blank=True)
    product_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)

    class Meta:
        db_table = 'tb_new_years_shopping_festival_elect_product'
        verbose_name = '年货节评选作品'
        verbose_name_plural = verbose_name


class NewYearsShoppingFestivalElectProductPic(models.Model):
    '''年货节评选作品'''

    product = models.ForeignKey('newyears.NewYearsShoppingFestivalElectProduct', on_delete=models.CASCADE, verbose_name='作品')
    image = models.ImageField(verbose_name='图片')

    class Meta:
        db_table = 'tb_new_years_shopping_festival_elect_product_pic'
        verbose_name = '年货节评选作品'
        verbose_name_plural = verbose_name


class NewYearsShoppingFestivalElectProductLike(models.Model):
    '''年货节评选作品点赞数'''

    product = models.ForeignKey('newyears.NewYearsShoppingFestivalElectProduct', on_delete=models.CASCADE,verbose_name='作品')
    create_time = models.DateTimeField(verbose_name='点赞时间', auto_now_add=True)
    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='点赞用户', on_delete=models.CASCADE)
    identification = models.CharField(verbose_name='标识', max_length=32, null=True, blank=True)
    day = models.CharField(verbose_name='日期', max_length=16, null=True, blank=True)

    class Meta:
        db_table = 'tb_new_years_shopping_festival_elect_product_like'
        verbose_name = '年货节评选作品点赞数'
        verbose_name_plural = verbose_name

